package com.weyoung.app.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.weyoung.app.dto.resp.BiographyEventsListByFamilyDTO;
import com.weyoung.app.dto.resp.BiographyUserListByCountDTO;
import com.weyoung.app.dto.resp.BiographyUserListDTO;
import com.weyoung.common.model.entity.Biography;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface BiographyMapper extends BaseMapper<Biography> {
//     @Select("SELECT " +
//            "ud.real_name, " +
//            "b.user_id, " +
//            "COUNT(b.biography_id) AS `count` " +
//            "FROM " +
//            "biography b " +
//            "JOIN " +
//            "user_detail ud ON b.user_id = ud.user_id " +
//            "WHERE " +
//            "b.family_id = ( " +
//            "    SELECT family_id " +
//            "    FROM user " +
//            "    WHERE user_id = #{userId} " +
//            ") " +
//            "GROUP BY " +
//            "b.user_id " +
//            "ORDER BY " +
//            "`count` DESC")
     List<BiographyUserListDTO> getBiographyListByUserId(int userId);

      @Select("SELECT " +
        "ud.real_name, " +
        "b.user_id, " +
        "COUNT(b.biography_id) AS number " +
        "FROM " +
        "biography b " +
        "JOIN " +
        "user_detail ud ON b.user_id = ud.user_id " +
        "WHERE " +
        "b.family_id = #{familyId} " +
        "GROUP BY " +
        "b.user_id " +
        "ORDER BY " +
        "number DESC")
    List<BiographyUserListByCountDTO> getBiographyUserListByCount(String familyId);
    @Select("SELECT b.biography_id, u.real_name as username, b.event_date, b.biography_title, b.biography_content, b.image_url_list " +
            "FROM biography b " +
            "JOIN user_detail u ON b.user_id = u.user_id " +
            "WHERE b.family_id = #{familyId} " +
            "AND b.is_deleted = '0' " +
            "And b.approval_status = '1'" +
            "ORDER BY b.event_date DESC")
    List<BiographyEventsListByFamilyDTO> getBiographyEventsListByFamilyId(String familyId);
}